package cn.edu.usst.cs.goldfish.booking.meetingroom.web.dto.booking;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

@Data
@Builder
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
@TableName("meeting_slot")
public class Slot {
    @TableField
    private LocalDate date;
    @TableField
    private Short hour;
    @TableField
    private Short segment;
    @TableField
    private Long meetingId;


    @TableField(exist = false)
    private Long roomId;
    @TableField(exist = false)
    @Builder.Default
    private String roomName = "Unknown";
    @TableField(exist = false)
    @Builder.Default
    private boolean occupied = false;
    @TableField(exist = false)
    @Builder.Default
    private String meetingTopic = null;

    @JsonIgnore
    public LocalDateTime getTime() {
        int minute = (segment - 1) * 10;
        minute = Math.max(minute, 0);
        LocalDateTime ret = LocalDateTime.of(date, LocalTime.of(hour, minute));
        log.debug("Slot: {} -> {}", this, ret);
        return ret;
    }

}
